import { Component } from '@angular/core';
import { Platform,IonicPage, NavController, NavParams,ViewController, AlertController , ModalController} from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { LoginPage } from '../login/login';

/**
 * Generated class for the SettingPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-setting',
  templateUrl: 'setting.html',
})
export class SettingPage {

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    private storage: Storage,
    private platform: Platform,
    private modalCtrl: ModalController,

    public viewCtrl: ViewController,
    private alertCtrl: AlertController


  ) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad SettingPage');
  }

  exitSoftware() {
    this.alertCtrl.create({
      title: '确认退出软件？',
      buttons: [{text: '取消'},
        {
          text: '确定',
          handler: () => {
            this.platform.exitApp();
          }
        }
      ]
    }).present();
  }
  loginout(){
    this.storage.ready().then(() =>{
      this.storage.clear();
    })

    this.viewCtrl.dismiss();
    this.navCtrl.push(LoginPage);

  }



  clearCache() {
    this.alertCtrl.create({
      title: '确认清除缓存？',
      subTitle: '清除后需要重新登录',
      buttons: [{text: '取消'},
        {
          text: '确定',
          handler: () => {
            this.storage.clear();
            let modal = this.modalCtrl.create(LoginPage);
            modal.present();
            modal.onDidDismiss(data => {
              this.navCtrl.popToRoot();
            });
          }
        }
      ]
    }).present();
  }

}
